% Tashfeen's complicated macros
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{hwcmd}[2023/01/01 hwcmd]

\RequirePackage{graphicx} % figures
\RequirePackage[caption=false]{subfig}
\RequirePackage{graphicx, pgffor, ifthen} % for loops and if statements
\RequirePackage[tableposition=below]{caption} % https://tex.stackexchange.com/a/424725/215221

\newlength{\unitskipamount}
\setlength{\unitskipamount}{\medskipamount}
\gdef\@unitname{Question}
\newcounter{UnitCounter}
\newcommand{\setunitname}[1]{\gdef\@unitname{#1}}
\newcommand{\question}[1][\arabic{UnitCounter}]{%
  \Needspace*{8\baselineskip}%
  \addvspace{\unitskipamount}%
  \def\@currentlabel{#1}%
  \ifthenelse{\equal{#1}{\value{UnitCounter}}}{\stepcounter{UnitCounter}}{}%
  \setcounter{section}{0}%
  \renewcommand{\thesection}{#1.\arabic{section}}%
  \renewcommand{\theHsection}{#1.\the\value{section}}%
  \addcontentsline{toc}{part}{#1. \@unitname{}}%
  \noindent\textbf{\@unitname{} #1. }\ignorespaces%
}

\newcommand{\fig}[4][0.4]{
  \begin{figure}[hbtp]
    \foreach \path in {#2} {
        \begin{minipage}{#1\textwidth}
          \centering % don't introduce new lines in \subfloat{...}
          \subfloat{\includegraphics[width=\linewidth]{\path}}
        \end{minipage} % minipage for easy centring
      }
    \caption{#3}\label{#4}
  \end{figure}
  \PackageWarning{hwcmd}{\noexpand\fig is deprecated, use \noexpand\img instead}
}

\ExplSyntaxOn
\NewDocumentCommand\img{d<>O{0.4}mm} {%
  \begin{figure}[hbtp]%
    \foreach \path [count=\i] in {#4} {%
        \ifthenelse{\equal{\i}{1}}{}{\hspace{0.25cm}}%
        \begin{minipage}{#2\textwidth}%
          \centering% don't introduce new lines in \subfloat{...}
          \subfloat{\includegraphics[width=\linewidth]{\path}}%
        \end{minipage}%
      }%
    \caption{#3}\IfValueT{#1}{\label{#1}}%
  \end{figure}%
}

\NewDocumentCommand\tbl{d<>mm} {%
  \begin{table}[hbtp]%
    \centering%
    \scribe_tbl:n { #3 }%
    \caption{#2}%
    \IfValueT{#1}{\label{#1}}%
  \end{table}%
}

\seq_new:N \l__scribe_tbl_body_seq
\seq_new:N \l__scribe_tbl_row_seq
\int_new:N \l__scribe_tbl_cols_int

\cs_new_protected:Nn \scribe_tbl:n {
  \seq_set_split:Nnn \l__scribe_tbl_body_seq { \\ } { #1 }
  \seq_pop_right:NN \l__scribe_tbl_body_seq \l_tmpa_tl
  \tl_if_empty:NF \l_tmpa_tl { \seq_put_right:NV \l__scribe_tbl_body_seq \l_tmpa_tl }
  \int_zero:N \l__scribe_tbl_cols_int
  \seq_map_inline:Nn \l__scribe_tbl_body_seq {
    \seq_set_split:Nnn \l__scribe_tbl_row_seq { & } { ##1 }
    \int_set:Nn \l__scribe_tbl_cols_int {
      \int_max:nn { \l__scribe_tbl_cols_int } { \seq_count:N \l__scribe_tbl_row_seq }
    }
  }
  \begin{tabular}{ ||*{\l__scribe_tbl_cols_int}{c|}| }
    \hline
    \seq_use:Nn \l__scribe_tbl_body_seq { \\ \hline }
    \\ \hline
  \end{tabular}
}
\ExplSyntaxOff